package com.yunxi.service.dubboService.impl.sat;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.model.sat.SatMess;
import com.yunxi.sat.pojo.SatMessVO;
import com.yunxi.sat.service.SatMessDubboService;
import com.yunxi.service.localService.sat.SatMessService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author
 * @since 2019-07-16
 */
public class SatMessDubboServiceImpl implements SatMessDubboService {

   @Autowired
   @Qualifier(value = "satMessServiceImpl")
   SatMessService satMessService;


   @Override
   public SatMessVO getById(String id) throws Exception {
      SatMess satMess = satMessService.getById(id);
      if(satMess != null){
         SatMessVO satMessVO = new SatMessVO();
         BeanUtils.copyProperties(satMess, satMessVO);
         //更新为已读
         satMess.setIsRead(1);
         satMessService.saveOrUpdate(satMess);
         return satMessVO;
      }
      else{
         throw new Exception("操作失败,无法根据id:"+id+"找到对应消息记录!");
      }
   }

   @Override
   public void saveOrUpdate(SatMessVO satMessVO) throws Exception {
      SatMess satMess = new SatMess();
      BeanUtils.copyProperties(satMessVO, satMess);
      satMessService.saveOrUpdate(satMess);
   }

   @Override
   public void removeById(String id) {
      satMessService.removeById(id);
   }

   @Override
   public PageInfo<SatMessVO> findPageByVO(SatMessVO satMessVO, Integer pageNum, Integer pageSize, LoginInfo loginInfo) throws Exception {
      String userCode = loginInfo.getUserCode();
      satMessVO.setSalesConsultantNo(userCode);
      PageInfo<SatMessVO> pageInfo = satMessService.pageByVo(satMessVO, pageNum, pageSize);
      return pageInfo;
   }

   @Override
   public void removeByListVo(List<SatMessVO> satMessVOList) throws Exception {
      satMessService.removeByListVo(satMessVOList);
   }

   @Override
   public List listByVo(SatMessVO satMessVO) {
      return satMessService.listByVo(satMessVO);
   }
}
